#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int solve(vector<int>& highs)
{
        int n = highs.size();
        if(n == 0) return 0;

        vector<int> dp(n, 1);
        for(int i = 1; i < n; i++){
                for(int j = 0; j < i; j++){
                        if(highs[i] > highs[j]){
                                dp[i] = max(dp[i], dp[j] + 1);
                        }
                }
        }

        reverse(highs.begin(), highs.end());
        vector<int> dp2(n, 1);
        for(int i = i; i < n; i++){
                for(int j = 0; j < i; j++){
                        if(highs[i] > highs[j]){
                                dp2[i] = max(dp2[i], dp2[j] + 1);
                        }       
                }
        }

        int maxv = -1;
        for(int i = 0; i < n; i++){
                maxv = max(maxv, dp[i] + dp2[n - i - 1] - 1);
        }
        return maxv;
}

int main()
{
        int n = 0;
        cin >> n;
        vector<int> highs(n, 0);
        for(int i = 0; i < n; i++){
                cin >> highs[i];
        }
        cout << solve(highs) << endl;
        return 0;
}